package com.service.web.controller.game;

import com.service.common.core.controller.BaseController;
import com.service.common.core.domain.AjaxResult;
import com.service.common.core.domain.entity.SysUser;
import com.service.common.core.domain.entity.TbUser;
import com.service.common.core.page.TableDataInfo;
import com.service.system.service.SysUserListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/game")
public class SysUserListController  extends BaseController {

    @Autowired
    private SysUserListService userListService;

    @GetMapping("/list")
    @PreAuthorize("@ss.hasPermi('game:user:list')")
    public TableDataInfo selectUserList(TbUser user){
        startPage();
        List<SysUser> list = userListService.selectUserList(user);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('game:user:edit')")
    @PutMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody TbUser user)
    {
        return toAjax(userListService.updateUser(user));
    }

    @PreAuthorize("@ss.hasPermi('game:user:edit')")
    @GetMapping("/selectById/{userId}")
    public AjaxResult selectById(@PathVariable(value = "userId", required = false) int userId)
    {
        AjaxResult ajax = AjaxResult.success();
        TbUser tbUser = userListService.selectTbUser(userId);
        ajax.put(AjaxResult.DATA_TAG, tbUser);
        return ajax;
    }

    @PreAuthorize("@ss.hasPermi('game:user:remove')")
    @DeleteMapping("/delete/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(userListService.deleteUserByIds(userIds));
    }



}
